﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.Security.Cryptography;
using System.Text;

namespace FastDeal.DTO
{
    public class User
    {
        public User()
        {
            Id = string.Empty;
            FullName = string.Empty;
            Pass = string.Empty;
            Phone = string.Empty;
            Email = string.Empty;
            Address = string.Empty;
            Created = DateTime.Today;
            Role = 1;
            IsActive=true;
        }

        [Required]
        public string Id { get; set; }

        public string Pass { get; set; }

        public string EncodePass
        {
            get
            {
                var md5 = new MD5CryptoServiceProvider();

                //compute hash from the bytes of text
                md5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(Pass));

                //get hash result after compute it
                byte[] result = md5.Hash;

                var strBuilder = new StringBuilder();
                for (int i = 0; i < result.Length; i++)
                {
                    //change it into 2 hexadecimal digits
                    //for each byte
                    strBuilder.Append(result[i].ToString("x2"));
                }

                return strBuilder.ToString();
            }
        }

        public string FullName { get; set; }

        public string Phone { get; set; }

        public string Email { get; set; }

        public string Address { get; set; }

        public int Role { get; set; }

        public DateTime Created { get; set; }

        public bool IsActive { get; set; }
    }
}